package com.wyc;

import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;


/**
 * @author
 */
@Activate(group = {CommonConstants.CONSUMER})
public class TPMonitorFilter implements Filter {

    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        String methodName = invocation.getMethodName();
        long startTime = System.currentTimeMillis();
        try{
            return invoker.invoke(invocation);
        } finally {
            long endTime = System.currentTimeMillis();
            long costTime = endTime - startTime;
            MethodCostTimeCount.put(methodName, endTime, costTime);
        }
    }
}
